import {gpFrontList} from '@/api/front'
export const mixins1 = {
  data() {
    return {
      dataList: [], //数据
      search: '', //搜索内容
      tabList: [
        //小导航数据
        { name: '推荐' },
        { name: '最新' },
        { name: '最近' },
      ],
      groupData: {}, //总条数
      pageNo: 1, //第几页
      pageSize: 20, //每页条数
      lat: 29.59, //默认北京定位 经度
      lng: 119.05, //维度
      frontType: '',
      frontFrom: '',
      iconType: 'flower', //加载图标样式
      status: 'loadmore', //加载的状态
      isLoading: false, //是否要加载数据
    }
  },
  onLoad(opt) {
    this.groupData = { ...opt }
    this.lng= uni.getStorageSync('lng');
    this.lat= uni.getStorageSync('lat');
  },
  methods: {
    loadmore() {
      // 每次出发该方法，都要使页数加一
      this.pageNo++
      this.gpFrontList()
    },
    //搜索
    onSearchBlur(v) {
      this.search = v
      this.onRest()
    },
    onRestFn(){
      this.pageNo = 1
      this.status = 'loadmore'
      this.isLoading = false
      this.dataList = []
    },
    //重置
    onRest() {
      this.onRestFn()
      this.gpFrontList()
    },
    //实时输入
    onSearchInput(e) {
      this.search =e
      if (e.length || e.trim()) {
        this.onRest()
      }
    },
    //阵地列表数据
    async gpFrontListData(_params) {
      const params = {
        frontName: `*${this.search}*`,
        lng: this.lng,
        lat: this.lat,
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        frontPublic: 1,
        frontHidden: 2,
        ..._params,
      }
      if (this.isLoading) {
        return
      }
      this.isLoading = true
      this.status = 'loading'
      uni.showLoading({
        title: '列表加载中...',
      })
      const {
        code,
        result: { records: list, total },
      } = await gpFrontList(params)
      if (code === 200) {
        this.isLoading = false
        uni.hideLoading()
        if (!list.length) {
          this.status = 'nomore'
        } else {
          this.status = 'loadmore'
          this.dataList = [...this.dataList, ...list]
          if (this.dataList.length >= total) {
            this.status = 'nomore'
          }
        }
      } else {
        this.status = 'nomore'
      }
    },
  },

  //加载到底部进行请求新的数据
  onReachBottom() {
    if (this.status === 'loadmore') {
      this.loadmore()
    }
  },
}
